﻿using System.Collections;
using System.Windows.Forms;

namespace ThreadSafeControls {
    public abstract partial class ThreadSafeListBox<TListBox> : ThreadSafeControl<TListBox>
        where TListBox : ListBox {
        
        protected readonly SelectedObjectCollection _selectedItems;
        protected readonly SelectedIndexCollection _selectedIndices;

        internal ThreadSafeListBox(TListBox listBox) : base(listBox) {
            _selectedItems = new SelectedObjectCollection(this);
            _selectedIndices = new SelectedIndexCollection(this);
        }

        public bool MultiColumn {
            get { return ReturnAsync(c => c.MultiColumn); }
            set { UpdateAsync(c => c.MultiColumn = value); }
        }

        public object SelectedItem {
            get { return ReturnAsync(c => c.SelectedItem); }
            set { UpdateAsync(c => c.SelectedItem = value); }
        }

        public SelectedObjectCollection SelectedItems {
            get { return _selectedItems; }
        }

        public int SelectedIndex {
            get { return ReturnAsync(c => c.SelectedIndex); }
            set { UpdateAsync(c => c.SelectedIndex = value); }
        }

        public SelectedIndexCollection SelectedIndices {
            get { return _selectedIndices; }
        }

        public bool Sorted {
            get { return ReturnAsync(c => c.Sorted); }
            set { UpdateAsync(c => c.Sorted = value); }
        }

        public void ClearSelected() {
            UpdateAsync(c => c.ClearSelected());
        }
    }
}
